#define F_CPU 8000000UL
#include<avr/io.h>

void SPI_slave_init(void)
{
	/* Set MISO output, all others input */
	DDRB = (1<<DDB4);
	/* Enable SPI */
	SPCR=(1<<SPE);  // SPI enable, Slave device 
}

unsigned char SPI_slave_receive(void)
{
	/* Wait for reception complete */
	while(!(SPSR & (1<<SPIF)));
	return SPDR;
}

int main(void)
{
	unsigned char rx_data;
	DDRC=0xFF;
	PORTC=0x00;
	SPI_slave_init();
	while(1)
	{
		rx_data=SPI_slave_receive(); 
		PORTC = rx_data;
	}
  return 0;
}
